package de.htwsaar.smog.model;

import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

/**
 * @author Thomas Schoenfeld
 * @date 2015-02-07
 * @version 20150207_01
 * 
 * Class Measurement describes an entity representing a measurement collection inside the MongoDB.
 * (db name: smog, collection: measurements)
 *
 */
@Document(collection = "measurements")
public class Measurement {

	// attributes
	
	@Id
	private String id;
	@Field(value = "sensor_id")
	private String sensorId;
	private String location;
	private String longitude;
	private String latitude;
	private String type;
	private Date time;
	private int value;

	
	
	// constructors

	/**
	 * Measurement class standard constructor
	 */
	public Measurement() {
	};

	/**
	 * Measurement class contructor
	 * 
	 * @param id
	 *            measurement id, automatically created by db
	 * @param sensorId
	 *            sensor id
	 * @param location
	 *            location name of the sensor unit
	 * @param longitude
	 *            geographic coordinate that specifies the east-west position of
	 *            a point on the Earth's surface
	 * @param langitude
	 *            geographic coordinate that specifies the north-south position
	 *            of a point on the Earth's surface *
	 * @param type
	 *            unit of measurement
	 * @param time
	 *            time of measurement
	 * @param value
	 *            value of measurement
	 */
	public Measurement(String id, String sensorId, String location,
			String longitude, String latitude, String type, Date time,
			int value) {
		this.id = id;
		this.sensorId = sensorId;
		this.location = location;
		this.longitude = longitude;
		this.latitude = latitude;
		this.type = type;
		this.time = time;
		this.value = value;
	}

	/**
	 * Measurement class copy constructor
	 * 
	 * @param measurement
	 *            Measurement object to copy
	 */
	public Measurement(Measurement measurement) {
		this(measurement.id, measurement.sensorId, measurement.location,
				measurement.longitude, measurement.latitude, measurement.type,
				measurement.time, measurement.value);
	}

	
	
	// getters and setters
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSensorId() {
		return sensorId;
	}

	public void setSensorId(String sensorId) {
		this.sensorId = sensorId;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Date getTime() {
		
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}
	
	
	
	// toString(), hashCode() and equals() - as it should
	
	@Override
	public String toString() {

		StringBuilder builder = new StringBuilder();
		builder.append("Measurement [id=").append(id).append(", sensorId=")
				.append(sensorId).append(", location=").append(location)
				.append(", longitude=").append(longitude).append(", latitude=")
				.append(latitude).append(", type=").append(type)
				.append(", time=").append(time).append(", value=")
				.append(value).append("]");
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((latitude == null) ? 0 : latitude.hashCode());
		result = prime * result
				+ ((location == null) ? 0 : location.hashCode());
		result = prime * result
				+ ((longitude == null) ? 0 : longitude.hashCode());
		result = prime * result
				+ ((sensorId == null) ? 0 : sensorId.hashCode());
		result = prime * result + ((time == null) ? 0 : time.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		result = prime * result + value;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Measurement other = (Measurement) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (latitude == null) {
			if (other.latitude != null)
				return false;
		} else if (!latitude.equals(other.latitude))
			return false;
		if (location == null) {
			if (other.location != null)
				return false;
		} else if (!location.equals(other.location))
			return false;
		if (longitude == null) {
			if (other.longitude != null)
				return false;
		} else if (!longitude.equals(other.longitude))
			return false;
		if (sensorId == null) {
			if (other.sensorId != null)
				return false;
		} else if (!sensorId.equals(other.sensorId))
			return false;
		if (time == null) {
			if (other.time != null)
				return false;
		} else if (!time.equals(other.time))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		if (value != other.value)
			return false;
		return true;
	}

}
